package com.dckeji.shiplock.webapp.controller.rest;

import com.dckeji.shiplock.framework.constants.SystemConstants;
import com.dckeji.shiplock.webapp.controller.BaseController;
import com.dckeji.shiplock.webapp.pojo.Evaluate;
import com.dckeji.shiplock.webapp.pojo.LogicRsult;
import com.dckeji.shiplock.webapp.service.IEvalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * Created with IntelliJ IDEA.
 * User: TianWei
 * Date: 2017/8/8
 * Time: 13:52
 * 评价
 */

@RequestMapping("/rest/eval/")
@RestController
public class EvalController extends BaseController {

    @Autowired
    IEvalService evalService;

    @RequestMapping("commit")
    public LogicRsult evaluate(@RequestBody List<Evaluate> evaluate) {
        LogicRsult logicRsult = new LogicRsult();
        int row = evalService.commitShipLockList(evaluate);
        if (row > 0) {
            logicRsult.setResultMsg(SystemConstants.ResultMsg.SUCCESS);
            logicRsult.setResultCode(SystemConstants.ResultCode.SUCCESS);
        } else {
            logicRsult.setResultMsg(SystemConstants.ErrorMsg.SYS_ERROR);
            logicRsult.setResultCode(SystemConstants.ResultCode.FIAL);
        }

        return logicRsult;
    }

    @RequestMapping("queryTime")
    public LogicRsult queryTime(@RequestBody Evaluate evaluate) {
        LogicRsult logicRsult = new LogicRsult();
        List<Evaluate> evaluates = evalService.queryTime(evaluate);
        if (null != evaluate && evaluates.size() > 0) {
            logicRsult.setResultMsg(SystemConstants.ResultMsg.SUCCESS);
            logicRsult.setResultCode(SystemConstants.ResultCode.SUCCESS);
            logicRsult.setObj(evaluates);
        } else {
            logicRsult.setResultMsg(SystemConstants.ErrorMsg.NO_DATA);
            logicRsult.setResultCode(String.valueOf(SystemConstants.ResultCode.NODATE));
        }
        return logicRsult;
    }


    @RequestMapping("query")
    public LogicRsult query(@RequestBody Evaluate evaluate) {
        LogicRsult logicRsult = new LogicRsult();
        List<Evaluate> evaluates = evalService.queryEvaluateInfos(evaluate);
        if (null != evaluate && evaluates.size() > 0) {
            logicRsult.setResultMsg(SystemConstants.ResultMsg.SUCCESS);
            logicRsult.setResultCode(SystemConstants.ResultCode.SUCCESS);
            logicRsult.setObj(evaluates);
        } else {
            logicRsult.setResultMsg(SystemConstants.ErrorMsg.NO_DATA);
            logicRsult.setResultCode(String.valueOf(SystemConstants.ResultCode.NODATE));
        }
        return logicRsult;
    }


}
